package it.unibo.mumu.util;

import it.unibo.mumu.entity.Planet;
import it.unibo.mumu.entity.Universe;
import it.unibo.mumu.entity.UniverseSelected;

import java.util.ArrayList;

public class SingletonSupport {
	
	private static SingletonSupport instance = null;
	
	private ArrayList<UniverseSelected> universes;
	private ArrayList<Universe> presentationUniverse;
	private int universeID;
	private int planetID;
	private int realUniverseID;
	private int realPlanetID;
	private int lastPlanetVisitedID;
	
	private boolean happiness;
//	private int realLastPlanetVisitedID;
	
	

	public static SingletonSupport getInstance() {
	    if (instance == null)
	            instance = new SingletonSupport();
	    return instance;
    }
	
	private SingletonSupport(){
		universes = new ArrayList<UniverseSelected>();
		presentationUniverse = new ArrayList<Universe>();
		universeID = -1;
		planetID = -1;
		realUniverseID = -1;
		realPlanetID = -1;
		lastPlanetVisitedID = -1;
		happiness = true;
	}
	
	public void setRealUniverseID(int val){
		this.realUniverseID = -1;
		for(int i=0; i<universes.size();i++){
			if(universes.get(i).getId() == val){
				this.realUniverseID = i;
			}
		}
	}
	
	public int findRealPlanetId(int dbValue){
		ArrayList<Planet> planetList = universes.get(realUniverseID).getPlanets();
		for(int i=0; i<planetList.size();i++){
			if(planetList.get(i).getIdPlanet() == dbValue)
				return i;
		}
		return -1;
	}
	
	public int getRealUniverseID(){
		return realUniverseID;
	}
	
	public void setRealPlanetID(int val){
		this.realPlanetID = -1;
		ArrayList<Planet> planetList = universes.get(realUniverseID).getPlanets();
		for(int i=0; i<planetList.size();i++){
			if(planetList.get(i).getIdPlanet() == val){
				this.realPlanetID = i;
			}
		}
	}
	
	public int getRealPlanetID(){
		return realPlanetID;
	}
	
	
	public void setUniverseID(int val){
		this.universeID = val;
	}
	
	public int getUniverseID(){
		return universeID;
	}
	
	public void setPlanetID(int val){
		this.planetID = val;
	}
	
	public int getPlanetID(){
		return planetID;
	}
	
	public void addUniverse(UniverseSelected u){
		universes.add(u);
	}
	
	public ArrayList<UniverseSelected> getUniverses(){
		return universes;
	}
	
	public void setUniverses(ArrayList<UniverseSelected> universes) {
		this.universes = universes;
	}

	public void addSimpleUniverse(Universe u){
		presentationUniverse.add(u);
	}
	
	public ArrayList<Universe> getSimpleUniverses(){
		return presentationUniverse;
	}
	
	public int getLastPlanetVisitedID() {
		return lastPlanetVisitedID;
	}

	public void setLastPlanetVisitedID(int lastPlanetVisitedID) {
		this.lastPlanetVisitedID = lastPlanetVisitedID;
	}
	
	public boolean isHappiness() {
		return happiness;
	}

	public void setHappiness(boolean happiness) {
		this.happiness = happiness;
	}

	public void clearAll(){
		universes.removeAll(universes);
		presentationUniverse.removeAll(presentationUniverse);
		universeID = -1;
		planetID = -1;
		realUniverseID = -1;
		realPlanetID = -1;
	}
	
}
